<?php
// load database class handler
include_once '../../../config/db_config.php';
include_once '../../../library/ezsql/shared/ez_sql_core.php';
include_once '../../../library/ezsql/mysql/ez_sql_mysql.php';

// database handler
$db = new ezSQL_mysql($dbUser, $dbPass, $dbName, $dbHost);

$bulan   	 = sprintf('%2d',$_POST['bulan']);
$jenis   	 = $_POST['jenis'];
$id 		 = $_POST['id'];
$no_individu = $db->get_var("SELECT `no_individu` FROM `caramel_managerial`.`pancang` WHERE `no_pancang`='".$id."'");


if($jenis == 'all'){
// get data real
$q = "
	SELECT 
        tgl_perawatan, 
        jenis,  
        nama, 
        jumlah, 
        satuan, 
        harga 
	FROM 
        caramel_operational.perawatan, 
        caramel_operational.perawatan_jenis, 
        caramel_operational.perawatan_material
	WHERE 
		no_individu = '".$no_individu."' AND
		MONTH(tgl_perawatan) = '".$bulan."' AND
		perawatan.id = perawatan_jenis.perawatan_id AND
		perawatan.id = perawatan_material.perawatan_id
	ORDER BY tgl_perawatan
	";
}
else{
// get data real
$q = "
	SELECT 
        tgl_perawatan, 
        jenis,  
        nama, 
        jumlah, 
        satuan, 
        harga 
	FROM 
        caramel_operational.perawatan, 
        caramel_operational.perawatan_jenis, 
        caramel_operational.perawatan_material
	WHERE 
		no_individu = '".$no_individu."' AND
		jenis = '".$jenis."' AND
		MONTH(tgl_perawatan) = '".$bulan."' AND
		perawatan.id = perawatan_jenis.perawatan_id AND
		perawatan.id = perawatan_material.perawatan_id
	ORDER BY tgl_perawatan
	";
}
		
$result = $db->get_results($q, ARRAY_A);
if( count($result) < 1 )
	die('tidak ada data');

	 
?>
	<div class="c">
	<?php
	foreach($result as $detail){
	?>
		<div class="title12" align="right"><?=$detail['tgl_perawatan'];?></div>
		<table class="material">
		  <tr>
			<td valign="top" width="150">Jenis</td>
			<td valign="top"width="10">:</td>
			<td><?=$detail['jenis'];?></td>
		  </tr>
		  <tr>
			<td valign="top" width="150">Nama Material</td>
			<td valign="top"width="10">:</td>
			<td><?=$detail['nama'];?></td>
		  </tr>
		  <tr>
			<td valign="top" width="150">Jumlah Material</td>
			<td valign="top"width="10">:</td>
			<td><?=$detail['jumlah'];?></td>
		  </tr>		  
	</table>
<?php
	} // end foreach
?>
		